<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$setting=$this->plugin_setting('setting');
	$plugins = $this->plugins();
	$bankuai1 =array(
		array('title'=>'美食/外卖','img'=>'../core/resource/images/diy/default/icon-1.png','action'=>'jy_dish/store_list/'),
		array('title'=>'酒店住宿','img'=>'../core/resource/images/diy/default/icon-2.png','action'=>'jy_jd/index/'),
		array('title'=>'休闲娱乐','img'=>'../core/resource/images/diy/default/icon-3.png','action'=>'jy_gohome/store/'),
		array('title'=>'周边商户','img'=>'../core/resource/images/diy/default/icon-4.png','action'=>'jy_cmso2o/list/'),
	);
	$setting['bankuai1'] =  !empty($setting['bankuai1']) ? $setting['bankuai1'] : $bankuai1;
	$setting['bankuai2'] =  !empty($setting['bankuai2']) ? $setting['bankuai2'] : $plugins[0]['list'];
	$footernav = array(
			array('title'=>'首页','icon'=>'icon-shouye','color'=>'#cc99ff','action'=>'jy_cms/index/','image'=>'../addons/jy_cms/resource/images/jy_cmsarticle.png'),
			array('title'=>'附件','icon'=>'icon-map','color'=>'#66cc99','action'=>'jy_cms/nearlist/','image'=>'../addons/jy_cms/resource/images/jy_fenleimsg.png'),
			array('title'=>'发现','icon'=>'icon-browse','color'=>'#ff9933','action'=>'jy_cms/foundlist/','image'=>'../addons/jy_cms/resource/images/jy_fenleimsg.png'),
			array('title'=>'订单','icon'=>'icon-manageorder','color'=>'#66cc66','action'=>'jy_cms/order/','image'=>'../addons/jy_cms/resource/images/jy_fenleimsg.png'),
			array('title'=>'我的','icon'=>'icon-wo1','color'=>'#FF83FA','action'=>'jy_cms/myhome/','image'=>'../addons/jy_cms/resource/images/jy_fenleimsg.png'),
	);
	$setting['footernav'] = !empty($setting['footernav']) ? $setting['footernav'] : $footernav;
	$return['list']=array();
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	$jy_gohome=pdo_get('core_plugins',array('name'=>'jy_gohome'));
	if(!empty($jy_gohome)){
		$worker_show=pdo_getall('jy_gohome_worker',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','status'=>'1','islock'=>'0'));
		if($worker_show){
			foreach($worker_show as &$item){
				$num1=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'1'));
				$num2=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'2'));
				$num3=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'4'));
				$item['num']=$num1+$num2+$num3;
			}
		}
		$serve_show=pdo_getall('jy_gohome_serve',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','status'=>'1'));
		if($serve_show){
			foreach($serve_show as &$item){
				$num1=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$item['id'],'status'=>'1'));
				$num2=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$item['id'],'status'=>'2'));
				$num3=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$item['id'],'status'=>'4'));
				$item['num']=$num1+$num2+$num3;
			}
		}
		$return['worker_show']=$worker_show;
		$return['serve_show']=$serve_show;
	}
	
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($post['page']));
	$psize = 8;
	$total='';
	$jy_jd=pdo_get('core_plugins',array('name'=>'jy_jd'));
	if(!empty($jy_jd)){
		$return['jdlist']=pdo_getslice('jy_jd_hotel',$params,array($pindex,$psize),$total,$fields,'','id desc');
		foreach($return['jdlist'] as &$v){
			$price=pdo_getall('jy_jd_room',array('hotelid'=>$v['id']));
			
			$price=json_decode($price['0']['taocan'],true);
			
			if(is_array($price)){
				paixu($price,'price');
			}
			$v['price']=$price['0']['price'];
			$v['lat_lng']=json_decode($v['lat_lng'],true);
			$v['juli']=cfc('tools')->getdistance($post['lng'],$post['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
			$v['juli']=intval($v['juli']/1000);
			$id=$v['id'];
			$_SESSION['juli'][$id]=$v['juli'];
		}
	}
	$return['setting']=$setting;
	set_html('title',$setting['title']?$setting['title'] :'地方门户');
	exi($return);
}
if($_RQ['op']=='list'){
	$post=get_postdata();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($post['page']));
	$psize = 10;
	$total='';
	$jy_dish=pdo_get('core_plugins',array('name'=>'jy_dish'));
	if(!empty($jy_dish)){
		$dishlist=pdo_getslice('jy_dish_store',$params,array($pindex,$psize),$total,$fields,'','display desc');
		if(empty($dishlist)){
			$dishlist = array(
				array('title'=>'莲庄客府-默认餐饮店')
			);
		}
		if($post['lat_lng']){
			foreach($dishlist as &$v){
				$v['lat_lng']=json_decode($v['lat_lng'],true);
				if($v['lat_lng']){				
					$v['distance']=cfc('tools')->getdistance($post['lat_lng']['lng'],$post['lat_lng']['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
					$v['distance']=intval($v['distance']/1000);
				}
				$v['ordernum']=pdo_count('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id >'=>$v['id']));
			}
			paixu($dishlist,'distance');
		}else{
			foreach($dishlist as &$v){
				$v['ordernum']=pdo_count('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id >'=>$v['id']));
			}
		}
	}else{
		$dishlist = array(
				array('title'=>'莲庄客府-默认餐饮店')
		);
	}
	$return['dishlist']=$dishlist;
	exi($return);
}	
?>